import java.util.Objects;

class Person{
    public String id;

    public Person(String id) {
        this.id = id;
    }

    @Override
    public String toString() {
        return "Person{" +
                "id='" + id + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
public class Test {
    public static void main(String[] args) {
        Person person1 = new Person("1234");
        Person person2 = new Person("1234");//生成的两个person的id是一样的，应该是同一个人
        System.out.println(person1.hashCode());
        System.out.println(person2.hashCode());
        //在没有重写equals和hashcode方法的时候hashcode生成的数值不一样
        //重写equals和hashcode方法后hashcode生成的数值一样

        HashBuck<Person, String> hashBuck = new HashBuck<>();
        hashBuck.put(person1,"lcc");//通过person1放数据
        String name = hashBuck.get(person2);//通过person2取数据，因为person1和person2是一样的，所以应该渠道“lcc”
        System.out.println(name);
    }
    public static void main1(String[] args) {
        HashBucket hashBucket = new HashBucket();
        hashBucket.put(1,11);
        hashBucket.put(2,22);
        hashBucket.put(12,122);
        hashBucket.put(3,33);
        hashBucket.put(4,44);
        hashBucket.put(14,144);
        hashBucket.put(5,55);
        hashBucket.put(16,166);
        System.out.println(hashBucket.get(16));
    }

}
